<template>
  <div id="basicLayout">
    <!-- 登录页面 -->
    <div class="login-register" v-if="route.path.startsWith('/user/login')">
      <router-view />
    </div>

    <!-- 主布局页面 -->
    <a-layout
      v-else-if="
        !route.path.startsWith('/user/login') && loginUserStore.loginUser.userName !== '未登录'
      "
      style="height: 100vh; overflow: hidden"
    >
      <!-- 顶部导航栏 -->
      <a-layout-header class="header">
        <GlobalHeader />
      </a-layout-header>

      <a-layout style="flex: 1; overflow: hidden">
        <!-- 左侧菜单 -->
        <a-layout-sider class="sider" width="260">
          <GlobalSider />
        </a-layout-sider>

        <!-- 右侧内容部分 -->
        <a-layout style="flex: 1; display: flex; flex-direction: column; overflow: hidden">
          <!-- 面包屑和内容区 -->
          <div
            style="
              flex: 1;
              display: flex;
              flex-direction: column;
              overflow: hidden;
              padding: 0 24px;
            "
          >
            <a-breadcrumb style="margin: 16px 0">
              <a-breadcrumb-item>首页</a-breadcrumb-item>
              <a-breadcrumb-item v-if="route.name !== '首页' && route.name !== '404'">{{
                secondTitle
              }}</a-breadcrumb-item>
              <a-breadcrumb-item v-if="route.name !== '首页'">{{ route.name }}</a-breadcrumb-item>
            </a-breadcrumb>

            <!-- 内容区域，超出滚动 -->
            <div class="content">
              <router-view />
            </div>
          </div>

          <!-- 底部 -->
          <a-layout-footer class="footer"> by 一个不知名程序猿 </a-layout-footer>
        </a-layout>
      </a-layout>
    </a-layout>
  </div>
</template>

<script setup lang="ts">
import GlobalHeader from '@/components/GlobalHeader.vue'
import GlobalSider from '@/components/GlobalSider.vue'
import { useRoute } from 'vue-router'
import { ref, watch } from 'vue'
import { useLoginUserStore } from '@/stores/useLoginUserStore.ts'

const route = useRoute()
const secondTitle = ref()

const loginUserStore = useLoginUserStore()

watch(
  () => route.fullPath,
  (newPath) => {
    if (newPath.startsWith('/user')) {
      secondTitle.value = '用户管理'
    } else if (newPath.startsWith('/teacher')) {
      secondTitle.value = '教师管理'
    } else if (newPath.startsWith('/student')) {
      secondTitle.value = '学生管理'
    } else if (newPath.startsWith('/academic')) {
      secondTitle.value = '教务管理'
    } else if (newPath.startsWith('/system')) {
      secondTitle.value = '系统管理'
    } else if (newPath.startsWith('/notice')) {
      secondTitle.value = '通知公告'
    } else if (newPath.startsWith('/access')) {
      secondTitle.value = '系统权限'
    } else if (newPath.startsWith('/stuUser/myScore')) {
      secondTitle.value = '我的成绩'
    } else if (newPath.startsWith('/teaUser/myStudent')) {
      secondTitle.value = '我的学生'
    } else if (newPath.startsWith('/teaUser/myGroup')) {
      secondTitle.value = '我的班级'
    } else if (newPath.startsWith('/visualization')) {
      secondTitle.value = '数据可视化'
    } else if (newPath.startsWith('/teaUser/notice') || newPath.startsWith('/stuUser/notice')) {
      secondTitle.value = '通知公告'
    }
  },
)
</script>

<style scoped>
.header {
  background-color: #3b5998;
}

.sider {
  //background-color: #001529;
  //overflow: auto;
}

.content {
  flex: 1;
  overflow: auto;
  background-color: #fff;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.footer {
  text-align: center;
  background: #f0f2f5;
  padding: 12px 0;
}

.login-register {
}
</style>
